﻿using System.Collections.Generic;
using EzDesk.DevHelper.FeedStudio.EzML;
using EzDesk.Utility.Log;

namespace EzDesk.DevHelper.FeedStudio.ToEzML
{
    public class EzMLBuilder
    {
        private readonly string _textSource;

        readonly List<EzMLProcessor> _processors = new List<EzMLProcessor>();

        public EzMLBuilder(string textSource, string sectionName)
        {
            this._textSource = textSource;

            _processors.Add(new LineBreakProcessor());
            _processors.Add(new StrongProcessor());
            _processors.Add(new WeakProcessor());
            _processors.Add(new ImptProcessor());
            _processors.Add(new UserInfoProcessor());
            _processors.Add(new NewLineProcessor());
            _processors.Add(new ReplacementProcessor());
            _processors.Add(new ReplaceTextProcessor());
            _processors.Add(new LinkProcessor());
            _processors.Add(new BasicInfoProcessor(sectionName));


        }

        public string Build()       
        {
            LogEx.TRACE("ToEzML ", "转换开始");
            LogEx.TRACE("ToEzML ", _textSource);
            string source = _textSource;
            foreach (var processor in _processors)
            {
                source = processor.Process(source);
                LogEx.TRACE("ToEzML", processor.GetType().Name);
                LogEx.TRACE("ToEzML ", source);
            }
            LogEx.TRACE("ToEzML ", "转换结束");
            return source;
        }
    }
}
